package com.huawei.hms.framework.network.restclient.hwhttp;

import com.huawei.hms.framework.network.restclient.hianalytics.RCEventListener;
import com.huawei.hms.framework.network.restclient.hwhttp.Interceptor.Chain;
import java.io.IOException;
import java.util.List;

public class RealInterceptorChain implements Chain {
    private HttpClient client;
    private final int index;
    private List<Interceptor> interceptors;
    private RCEventListener rcEventListener;
    private Request request;
    private RequestTask requestTask;

    public RealInterceptorChain(HttpClient httpClient, Request request, List<Interceptor> list, RCEventListener rCEventListener, int i, RequestTask requestTask) {
        this.client = httpClient;
        this.request = request;
        this.interceptors = list;
        this.index = i;
        this.rcEventListener = rCEventListener;
        this.requestTask = requestTask;
    }

    public RCEventListener getRCEventListener() {
        return this.rcEventListener;
    }

    public HttpClient getClient() {
        return this.client;
    }

    public Request request() {
        return this.request;
    }

    public Response proceed(Request request) throws IOException {
        return proceed(request, this.requestTask);
    }

    public Response proceed(Request request, RequestTask requestTask) throws IOException {
        if (this.index >= this.interceptors.size()) {
            throw new AssertionError();
        }
        Chain realInterceptorChain = new RealInterceptorChain(this.client, request, this.interceptors, this.rcEventListener, this.index + 1, requestTask);
        Interceptor interceptor = (Interceptor) this.interceptors.get(this.index);
        Response intercept = interceptor.intercept(realInterceptorChain);
        if (intercept != null) {
            return intercept;
        }
        throw new NullPointerException("interceptor " + interceptor + " returned null");
    }

    public RequestTask getRequestTask() {
        return this.requestTask;
    }
}
